<div style="width:680px; float:left; padding-left:5px; margin-left:5px"  class="content_right_group_admin box_shadow">

<?php

  		$ma = $_REQUEST['mauser'];

		if(is_numeric($ma) == true)

		{

			$ma = $ma;

		}

		else

		{

			$ma = 1;

		}

    	include_once("../../coms/xl_nguoidung.php");

		$user = new xl_nguoidung();

		$arr_user = $user->Load_nguoi_theo_ma($ma);

		

		

?>

  <h3> <span style="color:#006"> Cập nhật người dùng&nbsp; >> &nbsp;<?php echo $arr_user['tendangnhap']?></span></h3>

<br />



    <form name="fr_nguoidung" method="post" action="trangchu.php?key=upd_user&mauser=<?php echo $arr_user['manguoidung']?>" enctype="multipart/form-data">

  	<table width="60%" align="center" cellpadding="0" cellspacing="0">

        	<tr>

            	<td width="30%">Họ tên</td>

                <td><input type="text" name="txt_hoten" value="<?php echo $arr_user['hoten'] ?>" size="30" class="border_radius"/></td>

            </tr>

           

             <tr>

            	<td>Mật khẩu</td>

                <td><input type="password" name="txt_matkhau" value="<?php echo $arr_user['matkhau'] ?>" size="30" class="border_radius"/></td>

            </tr>

            <tr>

            	<td>Địa chỉ</td>

                <td><input type="text" name="txt_dc" value="<?php echo $arr_user['diachi'] ?>" size="30" class="border_radius"/></td>

            </tr>

             <tr>

            	<td>Email</td>

                <td><input type="text" name="txt_email" value="<?php echo $arr_user['email'] ?>" size="30" class="border_radius"/></td>

            </tr>

            <tr>

            	<td>Điện thoại</td>

                <td><input type="text" name="txt_dt" value="<?php echo $arr_user['dienthoai'] ?>" size="30" class="border_radius"/></td>

            </tr>

            <tr>

            	<td colspan="2" align="center">

                	<input type="submit" name="bt_capnhat" value="Cập nhập" class="button small blue"/>

                    <input type="button" name="bt_lamlai" value="Quay lại" class="button small blue"  onClick="javascript:window.location='trangchu.php?key=user'"/>

                </td>

            </tr>

            <tr>

            	<td><input type="hidden" name="txt_manguoidung" value="<?php echo $arr_user['manguoidung'] ?>" class="button small blue"/></td>

                <td ><input type="hidden" name="txt_tendangnhap" value="<?php echo $arr_user['tendangnhap'] ?>" size="30"/></td>

            </tr>

        </table>

    </form>



</div>



 <?php

 

if(isset($_POST['bt_capnhat']))

{

	$mauser = $_POST['txt_manguoidung'];

	$hoten = $_POST['txt_hoten'];

	$tendangnhap = $_POST['txt_tendangnhap'];

	$diachi = $_POST['txt_dc'];

	$dienthoai = $_POST['txt_dt'];

	$email = $_POST['txt_email'];

	

	$matkhau = md5(md5(md5(md5(trim($_POST['txt_matkhau'])))));

	$kt_tdn = new xl_nguoidung();

	$kq= $kt_tdn->kt_tendangnhap($tendangnhap);

	

	$kt_matkhau = new xl_nguoidung();

	$kq1= $kt_matkhau->kt_matkhau($matkhau);

	

	$kt = new xl_nguoidung();

	$kq2= $kt->kt_email($email);

	

	$flag=1;

	if($hoten == "")

	{

		echo "<script>alert('Vui lòng nhập họ tên')</script>";

		$flag=0;

	}

	else if($matkhau=="")

	{

		echo "<script>alert('Vui lòng nhập mật khẩu')</script>";

		$flag=0;

	}

	else if($email=="")

	{

		echo "<script>alert('Vui lòng nhập email')</script>";

		$flag=0;

	}

	else if(isset($kq1['manguoidung']))

	{

		echo "<script>alert('Vui lòng chọn mat khau khac')</script>";

		$flag=0;

	}

	else if(kt_kytu($hoten,$tendangnhap,$matkhau)==0)

	{

	$e = kt_kytu($hoten,$tendangnhap,$matkhau);

		echo "<script>alert('Vui lòng không nhập ký tự đặc biệt ngoài số và chữ')</script>";

		$flag=0;

	}

	else if(check_email($email)== false){

        echo "<script>alert('Mail không đúng định dạng')</script>";

		$flag=0;

	}

	

	if($flag==1)

	{

	//$hinh = $_POST["txt_hinh"];

	//echo $diachi;

	//echo $dienthoai;

	$sua_user = new xl_nguoidung();

	$now = getdate();

	$currentDate = $now["year"] . "-" . $now["mon"] . "-" . $now["mday"];

	$matkhau = md5(md5(md5(md5(trim($_POST['txt_matkhau']))))); 

	$ketqua = $sua_user->capnhap1($mauser,$hoten,$tendangnhap,$matkhau,$diachi,$dienthoai,$currentDate,$email);

	echo "<script>alert('Cập nhật thành công!!!')</script>";

	echo '<meta http-equiv="refresh" content="0;url=trangchu.php?key=user"  />';

	}

}



function kt_kytu($hoten,$tendangnhap,$matkhau)

{

	$kq=1;

	$specialChar="~`!@#$%^&*()-+=|\{}[]:;><,.?/".'"'; 

	for ($i=0; $i<strlen($specialChar); $i++) 

	{ 

		if (strpos($hoten, $specialChar[$i]) !==false || strpos($tendangnhap, $specialChar[$i]) !==false || strpos($matkhau, $specialChar[$i]) !==false) 

		{ 

			$kq=0;	

		} 

	} 

	return $kq;

}

function check_email($email) {  // hàm kiểm tra email

$to_work_out = explode("@", $email); 

  if (!isset($to_work_out[0])) return FALSE; 

  if (!isset($to_work_out[1])) return FALSE; 



  $pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$'; 

  $pattern_domain = '^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$'; 

  $match_local = eregi($pattern_local, $to_work_out[0]); 

  $match_domain = eregi($pattern_domain, $to_work_out[1]); 



  if ($match_local && $match_domain) { 

    return true; 

  } 

  return false; 

  }	

?>

